<?php
namespace plugins\task\controller;
use cmf\controller\PluginAdminBaseController;//引入此类
use plugins\task\model\TaskModel;
use think\Validate;
use app\common\lib\model_operate\Transit;

class AdminIndexController extends PluginAdminBaseController
{
    private static function getRootDec()
    {
        return APP_PATH."../public/upload/task";
    }
    private static function getAllowExt()
    {
        return [ 'txt' , 'json' , 'md'  ];
    }
    private static function getAllowUploadExt()
    {
        $allow = [ 'xls' , 'xlsx' , 'doc' , 'docx' , 'png' , 'jpg' , 'jpeg' , 'ico' , 'txt' , 'json'  , 'zip' , 'rar' , 'tag' , 'md' , 'sql' , 'pdf' , 'rp' , 'xmind' ];
        $allow = array_merge( $allow , self::getAllowExt() );
        $allow = array_unique( $allow );
        return $allow;
    }
	/**
	 * 任务管理-首页
	 */
    public function index()
    {
    	$param = $this->request->param();
        $page           = cmf_var_isset( $param , 'page' , 1 );
        $pagesize       = cmf_var_isset( $param , 'pagesize' , 10 );
        //任务类型：1.巡检任务、2.勘察任务、3.拍摄任务
        $task_type       = cmf_var_isset( $param , 'task_type' , '' );
        //模糊搜索：1.任务标题task_title；2.发布人员fabu；3.负责人员fuze；4.参与人员canyu；
        $search_name       = cmf_var_isset( $param , 'search_name' , '' );
        $search_value       = cmf_var_isset( $param , 'search_value' , '' );
        //任务状态：1.未开始、2.进行中、3.已超时、4.未完成、5.已完成、6.已取消
        $task_status       = cmf_var_isset( $param , 'task_status' , '' );
        //导航栏筛选：1.我发起的；2.我参与的；3.我负责的；4.下属负责的；
        $target =  cmf_var_isset( $param , 'target' , '' );

        $data = new TaskModel();
        if (!empty($task_type)) {
            $data = $data->where('task_type',$task_type);
        }
        if (!empty($search_name)) {
            $data = $data->where("$search_name",'LIKE',"%$search_value%");
        }
        if(!empty($task_status)){
            $data = $data->where('task_status',$task_status);
        }
        if(!empty($target)){
            $uid = cmf_get_current_admin_id();
            $user_login = db('user')->where('id',$uid)->value('user_login');
            switch ($target) {
                case 1:
                    $data = $data->where('fabu','LIKE',"%$user_login%");
                    break;
                case 2:
                    $data = $data->where('canyu','LIKE',"%$user_login%");
                    break;
                case 3:
                    $data = $data->where('fuze','LIKE',"%$user_login%");
                    break;
                case 4:
                    //下属name
                    $name = db('member')->where('parent_id',$uid)->value('name');
                    $data = $data->where('fuze','LIKE',"&$name%");
                    break;
                default:
                    break;
            }
        }
        // if(isset($param['depart_id']) && !empty($param['depart_id'])){

        //     $all_depart=db('department')->where(['is_del'=>2])->select()->toArray();

        //     $depart=db('department')->where('id',$param['depart_id'])->find();

        //     $depart_ids=$this->xiaji($all_depart,$depart['id']);
        //     // dump($depart_ids);die();

        //     $depart_ids[]=$depart['id'];

        //     $data = $data->where('station_id','IN',$depart_ids);
        //     // $where['resid']=['in',$depart_ids];
        // }
        $info = $data
            ->order('create_time','desc')
            ->paginate( $pagesize , false , [ 'page'=>$page ]  )
            ->each(function($v){
                $v['start_time'] = date('Y-m-d H:i:s',$v['start_time']);
                $v['end_time'] = date('Y-m-d H:i:s',$v['end_time']);
                switch ($v['task_type']) {
                    case 1:
                        $v['task_type'] = '巡检任务';
                        break;
                    case 2:
                        $v['task_type'] = '勘察任务';
                        break;
                    case 3:
                        $v['task_type'] = '拍摄任务';
                        break;
                    default:
                        break;
                }
                switch ($v['task_status']) {
                    case 1:
                        $v['task_status'] = '未开始';
                        break;
                    case 2:
                        $v['task_status'] = '进行中';
                        break;
                    case 3:
                        $v['task_status'] = '已超时';
                        break;
                    case 4:
                        $v['task_status'] = '未完成';
                        break;
                    case 5:
                        $v['task_status'] = '已完成';
                        break;
                    case 6:
                        $v['task_status'] = '已取消';
                        break;
                    default:
                        break;
                }
                switch ($v['task_level']) {
                    case 1:
                        $v['task_level'] = '普通';
                        break;
                    case 2:
                        $v['task_level'] = '重要';
                        break;
                    case 3:
                        $v['task_level'] = '紧急';
                        break;
                    case 4:
                        $v['task_level'] = '重要且紧急';
                        break;
                    default:
                        break;
                }
                if (!empty($v['file'])) {
                    $temp = explode('#.#', $v['file']);
                    foreach ($temp as $key => $value) {
                        $temp[$key] = zy_domain().$value;
                    }
                    $v['file'] = $temp;
                }
                return $v;
            });
        //导出表格
        // if(isset($param['export']) && $param['export'] == 1){
        //     $table = Transit::createTags('table');
        //     $table->export($info);
        // }
        $member = db('member')->column('id,name');
        return $this->fetch( 'index' , [
            'info'    =>  json_encode($info),
            'member'    =>  json_encode($member),
        ]);
    }
    /**
     *任务管理-初始页面-数据获取
     */
    public function getData()
    {
        $param = $this->request->param();
        $page           = cmf_var_isset( $param , 'page' , 1 );
        $pagesize       = cmf_var_isset( $param , 'pagesize' , 10 );
        //任务类型：1.巡检任务、2.勘察任务、3.拍摄任务
        $task_type       = cmf_var_isset( $param , 'task_type' , '' );
        //模糊搜索：1.任务标题task_title；2.发布人员fabu；3.负责人员fuze；4.参与人员canyu；
        $search_name       = cmf_var_isset( $param , 'search_name' , '' );
        $search_value       = cmf_var_isset( $param , 'search_value' , '' );
        //任务状态：1.未开始、2.进行中、3.已超时、4.未完成、5.已完成、6.已取消
        $task_status       = cmf_var_isset( $param , 'task_status' , '' );
        //导航栏筛选：1.我发起的；2.我参与的；3.我负责的；4.下属负责的；
        $target =  cmf_var_isset( $param , 'target' , '' );

        $data = new TaskModel();
        if (!empty($task_type)) {
            $data = $data->where('task_type',$task_type);
        }
        if (!empty($search_name)) {
            $data = $data->where("$search_name",'LIKE',"%$search_value%");
        }
        if(!empty($task_status)){
            $data = $data->where('task_status',$task_status);
        }
        if(!empty($target)){
            $uid = cmf_get_current_admin_id();
            $user_login = db('user')->where('id',$uid)->value('user_login');
            switch ($target) {
                case 1:
                    $data = $data->where('fabu','LIKE',"%$user_login%");
                    break;
                case 2:
                    $data = $data->where('canyu','LIKE',"%$user_login%");
                    break;
                case 3:
                    $data = $data->where('fuze','LIKE',"%$user_login%");
                    break;
                case 4:
                    //下属name
                    $name = db('member')->where('parent_id',$uid)->value('name');
                    $data = $data->where('fuze','LIKE',"&$name%");
                    break;
                default:
                    break;
            }
        }
        // if(isset($param['depart_id']) && !empty($param['depart_id'])){

        //     $all_depart=db('department')->where(['is_del'=>2])->select()->toArray();
            
        //     $depart=db('department')->where('id',$param['depart_id'])->find();

        //     $depart_ids=$this->xiaji($all_depart,$depart['id']);
        //     // dump($depart_ids);die();

        //     $depart_ids[]=$depart['id'];

        //     $data = $data->where('station_id','IN',$depart_ids);
        //     // $where['resid']=['in',$depart_ids];
        // }
        $info = $data
            ->order('create_time','desc')
            ->paginate( $pagesize , false , [ 'page'=>$page ]  )
            ->each(function($v){
                $v['start_time'] = date('Y-m-d H:i:s',$v['start_time']);
                $v['end_time'] = date('Y-m-d H:i:s',$v['end_time']);
                switch ($v['task_type']) {
                    case 1:
                        $v['task_type'] = '巡检任务';
                        break;
                    case 2:
                        $v['task_type'] = '勘察任务';
                        break;
                    case 3:
                        $v['task_type'] = '拍摄任务';
                        break;
                    default:
                        break;
                }
                switch ($v['task_status']) {
                    case 1:
                        $v['task_status'] = '未开始';
                        break;
                    case 2:
                        $v['task_status'] = '进行中';
                        break;
                    case 3:
                        $v['task_status'] = '已超时';
                        break;
                    case 4:
                        $v['task_status'] = '未完成';
                        break;
                    case 5:
                        $v['task_status'] = '已完成';
                        break;
                    case 6:
                        $v['task_status'] = '已取消';
                        break;
                    default:
                        break;
                }
                switch ($v['task_level']) {
                    case 1:
                        $v['task_level'] = '普通';
                        break;
                    case 2:
                        $v['task_level'] = '重要';
                        break;
                    case 3:
                        $v['task_level'] = '紧急';
                        break;
                    case 4:
                        $v['task_level'] = '重要且紧急';
                        break;
                    default:
                        break;
                }
                if (!empty($v['file'])) {
                    $temp = explode('#.#', $v['file']);
                    foreach ($temp as $key => $value) {
                        $temp[$key] = zy_domain().$value;
                    }
                    $v['file'] = $temp;
                }
                return $v;
            });
        //导出表格
        // if(isset($param['export']) && $param['export'] == 1){
        //     $table = Transit::createTags('table');
        //     $table->export($info);
        // }
        return api_json_echo(true,'',$info);
    }
    //循环查找下级组织部门
    // public function xiaji($xiaji,$pid){
        
    //     $ret = [];//定义空数组
    //     //循环遍历
    //     foreach($xiaji as $k => $v){
    //         if($v['parent_id'] == $pid){//如果上级id 和当前传递的id相等插入数组
               
    //             unset($xiaji[$k]);//删除已经插入数组的数据不然会无限循环
    //             $chlidren_depart = $this->xiaji($xiaji,$v['id']);//循环剩余的内容放到它的下级

    //             foreach ($chlidren_depart as $key => $value) {
    //                 $ret[] = $value;
    //             }

    //             $ret[] = $v['id'];//赋值到数组
    //         }
    //     }
    //     return $ret;
    // }
    /**
     *任务管理-添加页面
     */
    public function add(){
        $member = db('member')->field('id,name')->select();
        return $this->fetch( '' , [
            'member'    =>  json_encode($member),
        ]);
    }
    /**
     *任务管理-添加页面-数据提交
     */
    public function addPost()
    {
        $param = $this->request->param();
        //数据验证
        $validate = new Validate( [
            [ 'task_title' , 'require' , '任务标题不能为空' ],
            [ 'task_type' , 'require' , '任务类型不能为空' ],
            [ 'start_time' , 'require' , '开始时间不能为空' ],
            [ 'end_time' , 'require' , '结束时间不能为空' ],
            [ 'task_level' , 'require' , '紧要程度不能为空' ],
            [ 'fuze' , 'require' , '负责人员不能为空' ],
            [ 'fuze_id' , 'require' , '负责人员id不能为空' ],
            [ 'canyu' , 'require' , '参与人员不能为空' ],
            [ 'canyu_id' , 'require' , '参与人员id不能为空' ],
            [ 'road' , 'require' , '巡检点位不能为空' ],
        ] );
        if( !$validate->check( $param ) ){
            return api_json_echo(false ,$validate->getError());
        }

        //后台操作人员
        $uid = cmf_get_current_admin_id();  //id
        $user_login = db('user')->where('id',$uid)->value('user_login');

        $task_describe       = cmf_var_isset( $param , 'task_describe' , '' );//任务描述
        $mark = cmf_var_isset( $param , 'mark' , '' );//任务标记
        $file = cmf_var_isset( $param , 'file' , '' );//附件
        $fabu = $uid;//发布人
        $fabu_id = $user_login;//发布人id
        //名称查重

        //数据处理
        $start_time = strtotime($param['start_time']);
        $end_time = strtotime($param['end_time']);
        $fuze = implode('，', $param['fuze']);//负责人数组合并
        $fuze_id = implode('，', $param['fuze_id']);
        $canyu = implode('，', $param['canyu']);//参与人数组合并
        $canyu_id = implode('，', $param['canyu_id']);
        $file = implode('#.#', $file);//附件数组合并
        $file = str_replace(zy_domain(), '', $file);//附件去除域名
        $file = str_replace("\\", '/', $file); //附件路径去反斜杠,上传\变成/
        $task_status = (time()>$start_time)?2:1;//任务状态

        //新增
        $res = db('task')->insert( [
            'start_time'        =>  $start_time,
            'end_time'   =>  $end_time,
            'task_title'   =>  $param['task_title'],
            'task_type'   =>  $param['task_type'],
            'fuze'    =>  $fuze,
            'fuze_id'    =>  $fuze_id,
            'canyu'    =>  $canyu,
            'canyu_id'    =>  $canyu_id,
            'fabu'    =>  $fabu,
            'fabu_id'    =>  $fabu_id,
            'task_status'    =>  $task_status,
            'task_level'    =>  $param['task_level'],
            'task_describe' => $task_describe,
            'mark' => $mark,
            'file' => $file,
            'create_time' => time(),
            'road' => $param['road']
        ] );
        if ($res) {
            return api_json_echo(true,'添加成功');
        }else{
            return api_json_echo(false,'添加失败');
        }
    }
    /**
     * 上传文件
     */
    public function uploadFile( $file )
    {
        $param = $this->request->param();

        if(empty($file)) {
            return api_json_echo(false,'请选择上传文件');
        }

        //创建文件夹
        if( !$this->makeDec ( self::getRootDec() , date( "Ym" ) ) ){
            return false;
        }
        $path = self::getRootDec().'/'.date( "Ym" );//文件夹路径
        $info = $file
            ->validate(['size'=>512000,'ext' => self::getAllowUploadExt()])
            ->move( $path ,'' );//文件上传
        if( false === $info ){
            return api_json_echo(false,$file->getError());
        }
        $filename = $info->getSaveName();//获取文件（日期/文件名） 
        if( !$filename ){
            return api_json_echo(false,'文件保存失败');
        }
        $url_str = zy_domain().'/upload/task/'.date('Ym').'/'.$info->getSaveName();
        return api_json_echo(true,'',$url_str);
    }
    /**
     * 船舰文件夹
     */
    private function makeDec( $path , $decName )
    {
        if( $decName == '' ){
            $this->error = '目录名不能为空';
            return false;
        }
        if( !is_dir( $path ) ){
            $this->error = $path.'目录不存在';
            return false;
        }
        $path = $path.'/'.$decName ;
        if( is_dir( $path ) ){
            //目录已存在
            return true;
        }
        $isOk  = true;
        try {
            mkdir( $path , 0777 , true );
        } catch (\Exception $e) {
            $this->error = '异常:'.$e->getMessage();
            $isOk = false; 
        }
        $res = chmod( $path, 0777);
        if( !$isOk ){
            return false;
        }
        return true;
    }
    //图片上传
    // public function pzUpload(){
    //     $param = $this->request->param();

    //     //模块的标识
    //     $module = $param['_plugin'];

    //     //文件夹的标识
    //     $info = $param['info'];

    //     //获取上传的文件
    //     $file = $_FILES['file'];    

    //     $res = fileUpload($file,$module,$info);

    //     if($res['status'] == true){
    //         return json(['save'=>zy_domain().$res['data'],'info'=>$info]);
    //     }
    // }
    /**
     *任务管理-修改页面-数据获取
     */
    public function edit()
    {
        $param = $this->request->param();

        $validate = new Validate( [
            [ 'id' , 'require' , '请选择需要修改的项' ],
        ] );
        if( !$validate->check( $param ) ){
            return api_json_echo(false ,$validate->getError());
        }

        $data = db('task')->find($param['id']);
        if (empty($data)) {
            return api_json_echo(false,'数据不存在');
        }

        //数据处理
        $data['start_time'] = date('Y-m-d H:i:s',$data['start_time']);
        $data['end_time'] = date('Y-m-d H:i:s',$data['end_time']);
        $data['fuze_id'] = explode('，', $data['fuze_id']);
        $data['canyu_id'] = explode('，', $data['canyu_id']);
        $member = db('member')->field('id,name')->select();
        if (!empty($data['file'])) {
            $temp = explode('#.#', $data['file']);
            foreach ($temp as $key => $value) {
                $temp[$key] = zy_domain().$value;
            }
            $data['file'] = $temp;
        }

        return $this->fetch( '' , [
            'data'    =>  json_encode($data),
            'member'    =>  json_encode($member),
        ]);
    }
    /**
     *任务管理-修改页面-数据提交
     */
    public function editPost()
    {
        $param = $this->request->param();
        //数据验证
        $validate = new Validate( [
            [ 'task_title' , 'require' , '任务标题不能为空' ],
            [ 'task_type' , 'require' , '任务类型不能为空' ],
            [ 'start_time' , 'require' , '开始时间不能为空' ],
            [ 'end_time' , 'require' , '结束时间不能为空' ],
            [ 'task_level' , 'require' , '紧要程度不能为空' ],
            [ 'fuze' , 'require' , '负责人员不能为空' ],
            [ 'fuze_id' , 'require' , '负责人员id不能为空' ],
            [ 'canyu' , 'require' , '参与人员不能为空' ],
            [ 'canyu_id' , 'require' , '参与人员id不能为空' ],
            [ 'road' , 'require' , '巡检点位不能为空' ],
        ] );
        if( !$validate->check( $param ) ){
            return api_json_echo(false ,$validate->getError());
        }
        //后台操作人员
        $uid = cmf_get_current_admin_id();  //id
        $user_login = db('user')->where('id',$uid)->value('user_login');

        $task_describe       = cmf_var_isset( $param , 'task_describe' , '' );//任务描述
        $mark = cmf_var_isset( $param , 'mark' , '' );//任务标记
        $file = cmf_var_isset( $param , 'file' , '' );//附件
        // $fabu = $uid;//发布人
        // $fabu_id = $user_login;//发布人id

        //名称查重

        //数据处理
        $start_time = strtotime($param['start_time']);
        $end_time = strtotime($param['end_time']);
        $fuze = implode('，', $param['fuze']);//负责人数组合并
        $fuze_id = implode('，', $param['fuze_id']);
        $canyu = implode('，', $param['canyu']);//参与人数组合并
        $canyu_id = implode('，', $param['canyu_id']);
        $file = implode('#.#', $file);//附件数组合并
        $file = str_replace(zy_domain(), '', $file);//附件去除域名
        $file = str_replace("\\", '/', $file); //附件路径去反斜杠,上传\变成/
        // $task_status = (time()>$start_time)?2:1;//任务状态

        //添加修改记录,将旧数据与新数据比对,有变动的添加修改记录
        $old_info = db('task')->find($param['id']);   //获取旧数据
        // $edit_log = $old_info['edit_log'];   //存放修改记录的变量,保留历史修改
        $edit_log = '';                         //放弃历史修改
        //向$edit_log添加修改记录
        $edit_log = $edit_log.'【'.$user_login;//开始

        ($old_info['task_title'] == $param['task_title'])?:($edit_log = $edit_log.'将任务标题:'.$old_info['task_title'].'修改为'.$param['task_title'].'，'.date('Y-m-d H:i:s',time()).';');
        if ($old_info['task_type'] != $param['task_type']) {
            switch ($old_info['task_type']) {
                case 1:
                    $old_task_type = '巡检任务';
                    break;
                case 2:
                    $old_task_type = '勘察任务';
                    break;
                case 3:
                    $old_task_type = '拍摄任务';
                    break;
                default:
                    $old_task_type = '';
                    break;
            }
            switch ($param['task_type']) {
                case 1:
                    $new_task_type = '巡检任务';
                    break;
                case 2:
                    $new_task_type = '勘察任务';
                    break;
                case 3:
                    $new_task_type = '拍摄任务';
                    break;
                default:
                    $new_task_type = '';
                    break;
            }
            $edit_log = $edit_log.'将任务类型:'.$old_task_type.'修改为'.$new_task_type.'，'.date('Y-m-d H:i:s',time()).';';
        }
        ($old_info['start_time'] == $start_time)?:($edit_log = $edit_log.'将开始时间:'.date('Y-m-d H:i:s',$old_info['start_time']).'修改为'.$param['start_time'].'，'.date('Y-m-d H:i:s',time()).';');
        ($old_info['end_time'] == $end_time)?:($edit_log = $edit_log.'将结束时间:'.date('Y-m-d H:i:s',$old_info['end_time']).'修改为'.$param['end_time'].'，'.date('Y-m-d H:i:s',time()).';');
        if ($old_info['task_level'] != $param['task_level']) {
            switch ($old_info['task_level']) {
                case 1:
                    $old_task_level = '普通';
                    break;
                case 2:
                    $old_task_level = '重要';
                    break;
                case 3:
                    $old_task_level = '紧急';
                    break;
                case 4:
                    $old_task_level = '重要且紧急';
                    break;
                default:
                    $old_task_level = '';
                    break;
            }
            switch ($param['task_level']) {
                case 1:
                    $new_task_level = '普通';
                    break;
                case 2:
                    $new_task_level = '重要';
                    break;
                case 3:
                    $new_task_level = '紧急';
                    break;
                case 4:
                    $new_task_level = '重要且紧急';
                    break;
                default:
                    $new_task_level = '';
                    break;
            }
            $edit_log = $edit_log.'将紧要程度:'.$old_task_level.'修改为'.$new_task_level.'，'.date('Y-m-d H:i:s',time()).';';
        }
        ($old_info['task_describe'] == $task_describe)?:($edit_log = $edit_log.'将任务描述:'.$old_info['task_describe'].'修改为'.$task_describe.'，'.date('Y-m-d H:i:s',time()).';');
        ($old_info['fuze'] == $fuze)?:($edit_log = $edit_log.'将负责人员:'.$old_info['fuze'].'修改为'.$fuze.'，'.date('Y-m-d H:i:s',time()).';');
        if ($old_info['mark'] != $mark) {
            switch ($old_info['mark']) {
                case 1:
                    $old_mark = '红';
                    break;
                case 2:
                    $old_mark = '黄';
                    break;
                case 3:
                    $old_mark = '绿';
                    break;
                case 4:
                    $old_mark = '淡蓝';
                    break;
                case 5:
                    $old_mark = '深蓝';
                    break;
                case 6:
                    $old_mark = '紫';
                    break;
                default:
                    $old_mark = '';
                    break;
            }
            switch ($mark) {
                case 1:
                    $new_mark = '红';
                    break;
                case 2:
                    $new_mark = '黄';
                    break;
                case 3:
                    $new_mark = '绿';
                    break;
                case 4:
                    $new_mark = '淡蓝';
                    break;
                case 5:
                    $new_mark = '深蓝';
                    break;
                case 6:
                    $new_mark = '紫';
                    break;
                default:
                    $new_mark = '';
                    break;
            }
            $edit_log = $edit_log.'将任务标记:'.$old_mark.'修改为'.$new_mark.'，'.date('Y-m-d H:i:s',time()).';';
        }
        ($old_info['canyu'] == $canyu)?:($edit_log = $edit_log.'将参与人员:'.$old_info['canyu'].'修改为'.$canyu.'，'.date('Y-m-d H:i:s',time()).';');
        // ($old_info['file'] == $file)?:($edit_log = $edit_log.'将附件:'.$old_info['file'].'修改为'.$file.'，'.date('Y-m-d H:i:s',time()).';');

        $edit_log = $edit_log.';】';//结束
        //修改
        $res = db('task')->where('id',$param['id'])->update([
            'start_time'        =>  $start_time,
            'end_time'   =>  $end_time,
            'task_title'   =>  $param['task_title'],
            'task_type'   =>  $param['task_type'],
            'fuze'    =>  $fuze,
            'fuze_id'    =>  $fuze_id,
            'canyu'    =>  $canyu,
            'canyu_id'    =>  $canyu_id,
            // 'fabu'    =>  $fabu,
            // 'fabu_id'    =>  $fabu_id,
            // 'task_status'    =>  $task_status,
            'task_level'    =>  $param['task_level'],
            'task_describe' => $task_describe,
            'mark' => $mark,
            'file' => $file,
            // 'create_time' => time(),
            // 'road' => $param['road']
        ]);
        return api_json_echo(true,'修改成功');
    }
    /**
     *任务管理-页面-数据删除
     */
    public function delete()
    {
        $param = $this->request->param();
        if( !isset( $param [ 'id' ] ) || empty( $param [ 'id' ] ) ){
            return api_json_echo( false , '请选择要删除的项' );
        }
        if (is_array($param [ 'id' ])) 
        {
           $res = db('task')->where( 'id' , 'IN' , $param [ 'id' ] )->delete();
        }else
        {
            $res = db('task')->where('id',$param [ 'id' ])->delete();
        }
        if( !$res ){
            return api_json_echo( false , '删除失败' );
        }
        return api_json_echo( true , '删除成功' );
    }
}
